﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;
//using DataBaseConnection.ConnOrder;
using DataPagination;

public partial class UControls_ProSplitPage : System.Web.UI.UserControl
{
    PDataPage PDP = null;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    #region 成员
    string currURL = string.Empty;
    int maxRows = 20;
    string appQuery = string.Empty;
    object inSource;
    string splittype = "Common";
    int sourceid = 0;
    #endregion

    #region 属性
    /// <summary>
    /// 数据源编号
    /// </summary>
    public int SourceID
    {
        set { sourceid = value; }
        get { return sourceid; }
    }
    /// <summary>
    /// 页面索引
    /// </summary>
    public int PageIndex
    {
        get
        {
            //获取当前页索引
            int CurrentPage = 1;
            UIMethod.GetQuery(ref CurrentPage, "page");
            return (CurrentPage < 1) ? 1 : CurrentPage;
        }
    }
    /// <summary>
    /// 获取总记录数
    /// </summary>
    public int DataSourceCount
    {
        get { return PDP.DataSourceCount; }
    }
    /// <summary>
    /// 获取总页数
    /// </summary>
    public int PageCount
    {
        get { return PDP.PageCount; }
    }
    /// <summary>
    /// 当前分页页面
    /// </summary>
    public string CurrentURL
    {
        set { currURL = value; }
        get { return currURL; }
    }
    /// <summary>
    /// 页行数
    /// </summary>
    public int MaxRows
    {
        set { maxRows = value; }
        get { return maxRows; }
    }
    /// <summary>
    /// 追加参数.例：'name=leon&age=23&'
    /// </summary>
    public string AppendQuery
    {
        set { appQuery = value; }
        get { return appQuery; }
    }
    /// <summary>
    /// 数据源
    /// </summary>
    public object DataSource
    {
        set { inSource = value; }
    }
    /// <summary>
    /// 页面样式
    /// </summary>
    public string SplitType
    {
        set { splittype = value; }
    }
    /// <summary>
    /// 获取样式
    /// </summary>
    public string GetStyleHtml
    {
        get { return lil_output.Text; }
    }
    #endregion

    #region 方法
    /// <summary>
    /// 返回拆分的数据源
    /// </summary>    
    public DataView SplitSource()
    {
        //获取主要数据源
        DataSet ds = (DataSet)inSource;
        DataView sourData = ds.Tables[0].DefaultView;

        /******************* 处理页面样式 *******************/

        //获取数据总记录数
        int DataCount = 0;
        try { DataCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]); }
        catch { this.Visible = false; }

        //选择页面样式
        switch (splittype.ToUpper())
        {
            case "NUMBERBOUND":
                PDP = new SplitType_NumberBound();
                break;
            default:
                PDP = new SplitType_Common();
                break;
        }

        //返回样式
        PDP.URLHead = Page.ResolveUrl("~/");
        PDP.CurrentPageIndex = PageIndex;
        PDP.DataSourceCount = DataCount;
        PDP.PageSize = maxRows;
        PDP.PageURL = currURL;
        PDP.URLQuery = appQuery;

        lil_output.Text = PDP.GetSchema();

        return sourData;
    }
    #endregion     
}
